This article offers a fast method to install the Debian Stretch (Linux Debian 9) distribution on a Raspberry Pi2 or Pi3 nano-computer and also to add the softwares needed to set up a "weather and climate" project (Weewx, Jupyter, MRAA and UPM) or any project using the Raspberry Pi GPIO bus and effector or LED sensors. This is not a generic documentation but a description of a project which has been realized, which includes personal choices that can be modified : it thus allows one to realize an ad-hoc installation, corresponding to one's specific needs at some point. This installation is based on a work made by drtyhlpr which can be read here : rpy23-gen-image. As the Raspberry Pi described in this article runs on a Linux Debian system *this article assumes that the host machine interacting with the Raspberry Pi works under a Debian operating system * (no need for advanced knowledge in linux administration to follow this article). As an important part of the interaction is performed via a remote terminal or a terminal server, this method can also be executed from other computer environments.
Motivations
The "Météo et Climat tremplin pour l'enseignement des sciences" project (Climate and Meteorology springboard for STEM education) focuses on the instruments for measuring meteorological parameters and exploiting the resulting data, as well as the processing of meteorological and climatological data provided by Météofrance (the French national meteorological service). This interest has merged with the institutional will to teach coding.
This double interest has been realized through the use of nano-computers (Raspberry Pi, Odroĩd, Joule), which enables you to have genuine matchbox-sized multi-core processors at your disposal at an affordable price for an educational institution . These nano-machines allow you to create a measurement data interface working with sensors, to process and display data, or to write programs running on smartphone, tablet or other computer.
Initially simple consumers of technology, the student and his teacher can become actors and producers of resources which can be integrated into the universe of opendata. These nano-machines have direct access to the machine's low-level language (the basic level of the computer) and thus come up as blank pages which require some preliminary work of installation and configuration before we can express our technical scientific or design skills. This step is the core content of this article. In order to help those who simply wait for it to work or to support those who like to know how it works and do it themselves, we propose two different approaches:
-
For those who don't have much time to get into the details of the creation of the "image" (a file to download onto an SD card to boot the Raspberry Pi more easily), an "image" containing all the necessary tools for a Weather project is available for download. To install it directly on a micro-SD and operate the Raspberry Pi; Go to chapter 2 at the beginning of the article. The rest of the document describes the method which was used to create the image proposed online. This method can be adapted and modified to meet the needs of a project or to fit the pedagogical constraints of a given teaching.
-
For those who want to completely master the content of the machine they are going to use with their students, the process of image creation is fully described and should be reproduced (provided you have some numerical skills and a machine running under a free operating system; this work was done with a Debian stretch machine but any other linux distribution may be appropriate).
Thanks to
Carole Larose, Éric le Jan and Charles-Henri Eyraud for proofreading, advice and remarks. Charles-Henri Eyraud for his contribution to the image installation on an other OS than Linux.
Contents
-
a. Special features of the Raspberry Pi compared to a laptop
-
[Install the image on a microSD card and immediately start the Raspberry Pi (2 or 3)] (# head2)
a. Micro-SD preparation and construction
b. First start-up of the Raspberry Pi under the newly installed system
-
[How to build a Debian Stretch image] (# head3)
-
[Manual construction of Debian packages specifically used for the "Tremplin" project] (#head4)
a. The particular case of the weewx package
b. Building of the node package
c. Building of the swig package
d. Building the package libopenzwave
e. Building of the mraa package
-
a. Install a remote graphics terminal service
b. Various configurations for using Python with the GPIO bus
* Downloads *
- Image Creation Scripts
- weewx software
- swig software
- node v-6.9.1 software This version is required to compile mraa and upm correctly, the work is In progress to use [node v-7.7.0 software] (https://nodejs.org/dist/v7.7.0/node-v7.7.0-linux-armv7l.tar.xz
- mraa software
- upm software
- Client and Terminal Server
1. Overview of Raspberry Pi
A Raspbery PI 2 or 3 is a genuine "complete" computer with a processor, memory and storage space. It can be used as a desktop computer thanks to its HDMI connector allowing it to display on a screen, and to its USB port on which one can connect keyboard, mouse and any other device. It can also be used remotely as a terminal server : one just has to display the GUI (graphical user interface) on another computer (thanks to the HDMI port) or interact with it via remote raw command lines.
1.a Particularities of the Raspberry Pi compared to a laptop
The Raspberry Pi has several fundamental differences with a laptop.
The first difference is that the processor situated at the heart of the machine is a graphic processor built on an ARM architecture and not an X86 one. This may seem anecdotal to the user but it actually imposes some constraints which may ultimately have an impact on the common use.
The second one has to do with the memory, which is fixed and embedded in the processor. Its size is one of the limiting factors of the performance (the Odroïd nano-computers for example offer more memory and therefore a better comfort of use).
The third one concerns the storage, which is "removable" : the whole system and the users' storage space are on a micro-SD, and when you change micro-SD you actually get a different computer! It is therefore possible to create several profiles for several machines according to different needs at a reasonable cost.
The most crucial point is that the Raspberry Pi needs a small piece of formatted storage space to start, like that of USB keys (in FAT32), containing a proprietary binary code which depends on the processor used. It is therefore impossible to install a Raspberry Pi as we would install an ordinary laptop (interactively with a CD or a linux USB key). Because of this slight constraint, the most common method is to construct an "image" on an other computer and to copy it bit-by-bit onto the micro-SD media. This allows a user without advanced knowledge to download the image and copy it to the media. This is what we propose in the second part of this article. After that, we explain how to build one's own image (based on the model of the image needed for the "science springboard" project) by changing its parameters.
1.b First Strategic Choices
When a customer buys a computer, and even more a smartphone or a tablet, the seller describes in detail the many "turnkey services" offered by the object and the ease with which the user will get them, without ever talking about what this object (which is often a powerful computer) could do if other software choices had been made and often without informing the user of everything the device does without him knowing it.
For the Raspberry Pi you have on the one side a little inert electronic device, on the other side a blank SD memory card, you have to choose among 10 possible operating systems (as of 05/01/2017) what the heart of your machine will be like and what it will do. You are free to rely on any criterion, you can choose the OS that best suits your needs, your project, your desires, your skills and even your concerns about protecting your privacy or your militant positions.
I chose the Debian Stretch linux distribution because it enables to compile the tools I need for the "Weather and Climate Springboard project for science teaching" easily, and because the Raspberry Pi2 is equipped with a version 7 arm processor (armv7), which is part of the hardware for which we can find an online official Debian repository (with installation data and softwares everybody can download). The Raspberry Pi3 has an armv8 but the piece of code needed to make it work in 64 bits is still not available (as of 02/01/2017).
It is also possible to choose the kernel version from all those proposed on the site Raspberry Pi Linux git. In this project, the last version was chosen because it corresponded to the Debian Stretch kernel version.
2. Installing the image on a microSD card and immediately starting the Raspberry Pi (2 or 3)
It is necessary for the Raspberry Pi to be operational to have a microSD containing an image capable of booting. The site Raspberry Pi and many forums offer images with special goodies, but to facilitate the work of our colleagues working on the Tremplin project and in order to completely master the contents of the operating system, we realized an image containing the softwares we needed (called "image IFÉ-ENS of Lyon") and made it available on line. This image was conceived disregarding some functions which we didn't need. If you want to install these functions, you can recover the packages and integrate them to the computer (if there are really open packages or if sources are available for these functions : please note that it is not because the Raspberry Pi is a open device that all the software that run on it are open as well...).
The speed of the Raspberry Pi depends heavily on the writing speed of the SD. Class 10 SD cards (with a 10 Mo/s speed) are rather deprecated : it is better to choose a Ultra-high speed SD card (UHS-I or UHS-II), and note that speed often depends on the price. But be careful to check the writing speed, which can be very different from the playback speed.
The installation described here is realized via command line instructions typed from a machine running under linux Debian. As the Raspberry Pi runs by default under linux, this mode of installation is quite spontaneous and also extremely robust. You can find tutorials explaining how to install the image with other OSs which are perfectly compatible with the image proposed here (for instance with Windows). Few tips are given below to install the image from a machine under Windows. If you do not have a Debian machine and want to follow this manual, you can start your computer on a live Debian session. This will not alter your computer and it will restore it to its normal state after the live session. You will find here the method to create a bootable USB key for Debian (a USB key from which a computer can install a different operating system). _ (Any other linux distribution should also work, by the way.) _
To manage the SD card and the installation of the image you will need the softwares gparted, wget, 7z and bmap-tools
.
For the latter, version 3.2 is required to use the file provided for download. If the computer you are using has another version, 2.5 for example, you will imperatively need to redo the .bmap file by applying this command line :
bmaptool create -o image_name.bmap image_name
The expression image_name correspond to the name of the file provided by the IFE-ENS-de-Lyon on the download site (see below).
2.a Micro-SD preparation and construction
Format SD
under linux It is always better to "clean" your micro SD and format it properly before you start. Format your SD in fat32 : the command to do this work under linux is gparted, which offers also a graphical interface. Warning : this command is extremely powerful, make sure to treat your SD only (and especially not any other disk or partition.) Your SD should spontaneously appear under a mmcblk? type of name.
sudo gparted
Use the gparted
commands in the drop-down menus to delete partitions if any, then select the entire surface and add a single primary partition to fat32. Execute the operation and exit gparted
.
Format SD with other OS
If you want to use a pre-formatted SD for the RaspberryPi, you'll still need to format it. But since Windows doesn't naturally recognize the ext4
file system, you will have to install on your computer a software which provides this function, for instance ext2fsd (Read Write ext4).
Download the image provided
The image can be found on the mediaserver of the "Tremplin des sciences" project. The YYYY-MM-DD numbers represent the creation date to be set, based on what is available online. To get this number connect with a web browser to Raspberry Pi3 http://mediaserv.climatetmeteo.fr/images/RaspBerry/DebianStretchPi3
or Raspberry Pi2 http://mediaserv.climatetmeteo.fr/images/RaspBerry/DebianStretchPi2
.
To download the image, copy and paste the image's name in the address bar and the download will be launched, or use the linux command wget
orcurl
. Because of the hardware and peripheral devices, images are different for Raspberry Pi 2 and 3; they might be compatible but their correct functioning is not guaranteed.
Raspberry Pi 2
wget http://mediaserv.climatetmeteo.fr/images/RaspberryPi/DebianStretchPi2/YYYY-MM-DD-debian-stretch.bmap
wget http://mediaserv.climatetmeteo.fr/images/RaspberryPi/DebianStretchPi2/YYYY-MM-DD-debian-stretch.img.xz
Raspberry Pi 3
wget http://mediaserv.climatetmeteo.fr/images/RaspberryPi/DebianStretchPi3/YYYY-MM-DD-debian-stretch.bmap
wget http://mediaserv.climatetmeteo.fr/images/RaspberryPi/DebianStretchPi3/YYYY-MM-DD-debian-stretch.img.xz
Unzip the downloaded image
The image is in compressed (or zip) format, and it is necessary to unzip it with one of the many unzipping tools available (here we use 7Z):
7z x YYYY-MM-DD-debian-stretch.img.xz
For the .bmap file you must right click on the link and ask "save the target of the link under" to avoid the browser opening the file.
The decompression provides the image file, after this operation we therefore have:
- A small first file with the bmap extension which is a configuration file allowing a quick copy with the bmap-tool utility (this file is useless if you use a less powerful operating system not knowing how to exploit the description of the image)
- The image itself of large size (of the order of 7.5GB) with the extension img
Copy the downloaded image to the microSD
The bmap-tools utility uses the description of the image to be copied to shorten the copy time by not copying the empty blocks and optimizing the size of the copied blocks. Below is a sample copy of the rp3 and rpi2 image.
sudo bmaptool copy --bmap YYYY-MM-DD-debian-stretch.bmap YYYY-MM-DD-debian-stretch.img /dev/mmcblk0
bmaptool: info: block map format version 2.0
bmaptool: info: 921600 blocks of size 4096 (3.5 GiB), mapped 899072 blocks (3.4 GiB or 97.6%)
bmaptool: info: copying image 'YYYY-MM-DD-debian-stretch.img' to block device '
bmaptool: info: 100% copied
bmaptool: info: synchronizing '/ dev / mmcblk0'
bmaptool: info: copying time: 8m 3.9s, copying speed 7.3 MiB / sec
Resize the usable size to the size of the micro SD
The image occupies only the space necessary to contain the system and the basic files (with a little margin for the stunned), it is desirable as soon as possible to increase the size of the partition to the total size of the MicroSD to have the place to put other software or data. Depending on your habits and your mastery you can create several partitions at this time if you want to create several partitions (Do not commit to creating more partitions if you do not know how to do it because it will also be necessary to modify the configuration file of the system / etc / Fstab
so that it works). To resize the partition two procedures are possible:
Using the third-party computer
Eject and reassemble the microSD before starting the size modification, reuse gparted always with the same caution recommendations .
sudo gparted
Exit gparted
eject the microSD and install it on the Raspberry Pi, you now have an operational Raspberry Pi ready for the weather and programming! To use it, you have to slide the SD into the slot, connect the Raspberry Pi to the network and a micro-USB power supply and you will be able to go! This connection is enough to be operational but for the first time especially if one is not accustomed to the linux command line it is desirable to also connect a screen a keyboard and a mouse .... and we find ourselves in front of a true computer (See below)
Using the newly installed Raspberry Pi
In some cases problems may occur with resized SDs with gparted
(you will find on the web an abundant literature on performance and Weaknesses of different micro-SDs if you have not chosen a "low-end" SD you should not be concerned with these problems, but ... you never know). In other cases, the older version of gparted does not handle the metadata_csum
parameter and can not resize the root partition. In these two cases gparted
is unusable and the above solution is unavailable and the solution below using Raspberry Pi is mandatory. To avoid usinggparted
and the third-party computer it is possible to resize the partition Root directly on the Raspberry Pi running with the new image. To do this once the Raspberry Pi is operational and started use the command
sudo fdisk /dev/mmcblk0
- Type
m
to see the list of commands (just for information) - Type
P
to see the list of available partitions, normally there are two- a FAT: / dev / mmcblk0p1 * 2048 133119 131072 64M c W95 FAT32 (LBA)
- a linux: / dev / mmcblk0p2 133120 62517247 62384128 29.8G 83 Linux
- Then type
d
then2
thenn
thenp
then2
then- accept the default values that correspond to the actual size available on the SD cards and write N for" Remove signature ",
- to end type
w
. Then typesudo reboot
then:
sudo resize2fs / dev / mmcblk0p2sudo reboot
After this second restart, the system root now occupies the entire available space on the SD.
Reconfiguration of the wired network
In the case of the Raspberry Pi2, depending on the options chosen for the construction it may be necessary to carry out some manual manipulations which will facilitate the subsequent work. For example, in our case we want to directly access the WIFI for this we put in the installation the necessary driver package (firmware-realtek), if you have another hardware it will be necessary to install the correct driver.
It is important that the users belong to the netdev group in order to modify the network configuration. To do this, modify the /etc/group
file of the newly copied card, (do not put the users in this group is a method to limit their access on a specific Internet network). The manipulation can be done directly on the card mounted on the third-party computer (without installing it on the Raspberry Pi) modify the line netdev like this netdev: x: 108: ens-ife
, this work is already done for Pre-installed users ens-ife, localadm, callisto, moon ...
We just clone an image which means that all the configuration files are identical with the source image. This has many advantages but some disadvantages. One of them is that the network adapter ID of the original source machine is likely to be kept in the network configuration files (this is not systematic but if this happens, then apply the procedure below).
It is imperative for the network to work correctly that the configuration files are empty on the first connection of the new machine to the network (and in particular to the wired). The easiest and most intuitive way to do this is to start with a complete environment: keyboard, screen, mouse; And to use the graphic tools to configure the network.
It is also possible to do the operations that are carried out from the GUI by hand in configuration files, these manual operations are to be done rather by advanced users , But in case of problem any user can find in the files useful information. Verify that the files ending in .conf
in the /etc/wicd
directory are empty, if they are not, do the following commands:
sudo rm /etc/wicd/wired-settings.conf
sudo rm /etc/wicd/wireless-settings.conf
sudo touch /etc/wicd/wired-settings.conf
sudo touch /etc/wicd/wireless-settings.conf
It is also imperative to identify the name of the wired interface And enter it in the manager-settings.conf
file, to get the name hit :
ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2:enxb827eb3c732f: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether b8:27:eb:3c:73:2f brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:69:26:7a brd ff:ff:ff:ff:ff:ff
inet 10.0.1.14/24 brd 10.0.1.255 scope global wlan0
valid_lft forever preferred_lft forever
inet6 fe80::ba27:ebff:fe69:267a/64 scope link
valid_lft forever preferred_lft forever
The name of the interface is here enxb827eb3c732f .
The contents of the manager-settings.conf
file should look like this:
[Settings]
backend = external
wireless_interface = wlan0
wired_interface = nom_de_l'interface_filaire
wpa_driver = wext
always_show_wired_interface = True
.../...
2.b First start of the Raspberry Pi on the newly installed system
Install the micro-SD in the connector provided and connect the RPi via the micro-USB connector. With a Raspberry Pi3 it is not necessary to be connected as wired because the image contains the driver of the WIFI which can be activated by default, however for the WIFI connection it is necessary to provide the connection information (name Network and password) before start the Raspberry Pi (see above). It is therefore recommended for the first connection to be connected via the wired network.
For the Raspberry Pi2 if a USB WIFI is present and if the package containing the drivers has been installed it is in the same situation. On the other hand if the Raspberry Pi2 does not have a WIFI it must be wired to reach the network (no WIFI integrated by default in the Raspberry Pi2) and install the necessary package; Here it would be for example the package realtek (which is already installed in the image IFÉ ENS of Lyon):
sudo apt-get install firmware-realtek
For the first connection it is also desirable / comfortable to have a complete screen / keyboard / mouse environment that makes the Raspberry Pi accessible in an "ordinary" way, the console has been deactivated in this image and therefore does not allow to have Access to the Raspberry Pi via this degraded mode. The screen displays a login prompt:
- Available logins are
- ens-ife (set up for team members in case of need for remote support),
- localadm (local administrator of Raspberry Pi),
- callisto (owner and launcher of Jupyterhub)
- moon (regular test user)
- The start password of the first 2 accounts outside ens-ife is AChanger1 $ (which suggests that it must be changed as soon as possible!) That of moon is guest.
Once in the work environment access the wicd tool to configure the network (see above). We can then continue to work "ordinary" with an active internet connection.
However it is possible to progress in a "less intuitive" but just as effective (command line) way by connecting to the Raspberry Pi via a terminal is what is described below. The only constraint is to have the IP address of the Raspberry Pi to which you connect with the localadm user from a third-party computer using the following commands:
ssh localadm@***.***.***.***
The authenticity of host '***.***.***.*** (***.***.***.***)' can't be established.
ECDSA key fingerprint is SHA256:J4MATvTmHHoSu/Lkz2auFWTJwCgaZTqRBVMIDoshpA4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '***.***.***.***' (ECDSA) to the list of known hosts.
localadm@***.***.***.***'s password:
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Setting up basic comfort
The initial users ens-ife and localadm are privileged users. * It is dangerous to work on the privileged user * while it is possible and quick to create as many users as necessary (all ordinary users will have to be created with the method below). Create a user and continue in the space of this user, it is possible to work as a user moon
, the ompte was preconfigured by default.
sudo adduser myUser
Answer questions using no accented characters or special characters (except for the password). It is also useful to place this user in a certain number of groups in order to facilitate daily operation:
- The i2c group to access the i2c bus and the sensors it carries
- The gpio group to access the gpio bus
- Netdev group to access the network settings.
- Jupyter group to access the services of jupyterhub
sudo adduser myUser netdev
sudo adduser myUser gpio
sudo adduser myUser i2c
sudo adduser myUser jupyter
2.c Using the RaspPi Remote Graphically
The use of the command line is not necessarily easy to access for many users and it is useful to provide a remote graphical interface for users who do not know or can not adapt to the command line . The solution involves setting up a terminal server on the Raspberry Pi associated with a client that displays the Raspberry Pi remote screen. The terminal server on the Raspberry Pi is installed by default and the service is set up but not enabled. This service is useful only if you want to connect via a remote graphics environment; Otherwise it is desirable to keep it deactivated (see below). For an unknown reason even when activated, the service refuses to start automatically to the boot so it must be launched by hand. To do this connect remotely with a console knowing the IP address of the Raspberry Pi and issue the command:
ssh localadm@xxx.xxxxxx.xxx sudo --stdin service vncserver start
The server starts and provides online access. To connect to this graphics terminal server provide the customer with the following information:
- Login: callisto
- Password: the one that was delivered the first time the server started
- Address xxx.xxx.xxx.xxx:1
- Port 5901
On this figure remmina was used.
To turn off the remote service
ssh localadm@xxx.xxxxxx.xxx sudo --stdin service vncserver stop
If the terminal server is not yet activated (it is proposed as a service in the proposed image but not necessarily activated by default [this point is under discussion because of the security consequences]), To run it and retrieve a graphic mode you need a password that is created at the first launch of vncserver as in the example below, we use (the password is preserved and does not perish, you need a command to change him) :
localadm@raspife3:~$ vncserver
You will require a password to access your desktops.
Password:
Verify:
Would you like to enter a view-only password (y/n)? n
New 'X' desktop is raspife3:1
Creating default startup script /home/ens-ife/.vnc/xstartup
Starting applications specified in /home/ens-ife/.vnc/xstartup
Log file is /home/ens-ife/.vnc/raspife3:1.log
ens-ife@raspife3:~$
It is then possible to display the screen of the Raspberry Pi on the screen of any computer using a terminal server client, for example the opensource client Tightvncserver.
Setting up a VNC broadcast on port 5901
The systematic solution of the service consumes resources and is set up by default. A less elegant way to get a graphical display is that each user * myUser * can launch a terminal server to his / her name to do this by adding to the /etc/rc.local file for each user " myUser " the line next :
su myUser -c / usr / bin / vncserver
As in the previous case at the first launch of vncserver by the user myUser it is necessary to choose the password of the terminal server or have fixed it in advance with the command:
vncpasswd
Executed as myUser.
Whether using the default terminal server or a custom server it is desirable before terminating the Raspberry Pi to terminate the terminal servers either by terminating the service or by using the following command for each user:
vncserver -kill: 1
Finding the MAC address or recognizing the WIFI interface
To implement this solution we must know the MAC address of its WIFI interface for this we use the ip instruction on the Raspberry Pi:
ip addr show
Which provides in the event that the Raspberry Pi has taken IP 192.169.11.120:
3: wlan0: <BROADCAST, MULTICAST, UP, LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
Link / ether **:**:**:**:**:** brd ff:ff:ff:ff:ff:ff
Inet 192.169.11.120/24 brd 192.169.11.255 scope global dynamic wlan0
Valid_lft 9165sec preferred_lft 9165sec
Inet6 $$$$ :: $$$$: $$$$: $$$$: $$$$ / 64 scope link
Valid_lft forever preferred_lft forever
Where * *:**:**:** is the unique MAC address of the interface. You must have the machine that will serve as a client for the terminal on the same network and look for the address of the Raspberry Pi card (you need administrative rights):
sudo nmap -sP -n 192.169.11.0/24 | Grep -e **: **: **: **: **: ** -B 2
Caution some network administrators do not like (at all, at all) that a lambda user uses this privileged command and is deemed 598/5000 Aggressive because it allows to obtain information on the network, in this case you will not get any answer or you will see disembarking in the office the security of the establishment .... However if you do not repeat it a hundred of Once you have recovered your IP you are in a known situation and you can connect from a terminal:
ssh 92.169.11.120 vncpasswd (give a session password ) Vncserver
Then a VNC client and the screen of the Raspberry Pi appears on your machine ....
2.d Updates: System, mraa, and upm
This keeps the operating system consistent.
System Update
Depending on the time between the construction of the image and the installation, this may take time and consume bandwidth, only when you have sufficient time and fast connection.
apt-get update
apt-get upgrade
apt-get dist-upgrade
Updating mraa and upm
Mraa and upm are opensources libraries supported by Intel and an important and very active community, it is possible that the version compiled in the image is not sufficiently up to date (for example a significant contribution was made on the code of a Sensor you are interested in) and in this case it is necessary to retrieve the latest version online and compile it. This is facilitated by the structure in place. To update mraa two situations are possible:
If the mraa and upm repositories are already cloned (which is the case in the ENS-IFÉ image)
In this case there is a Software / IoT / mraa and Software / iOt / upm directory in the storage space of the default administrator (localadm) in this case:
- Update repositories from the online resource
- Enter the build folder
- prepare compilation with the cmake instruction
- compiler installer
- the new version is available!
Attention in the oldest images the build directory is named Build
instead of build
the rest of the procedure remains the same.
cd ~/Logiciels/IoT/
cd mraa/
git pull
.../...
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make -j4
sudo make install
cd ../../upm
git pull
.../...
cd build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make -j4
sudo make install
Usually the compilation happens without problems but sometimes insufficiently verified contributions cause errors that are corrected quickly:
- Either you can wait for correction,
- Either the affected driver does not interest you and you remove it from compilation with the command:
rm -r ../src/nameOfDeletedDriver
- Either you recognize the error in the code and you can correct the source!
If the deposits are not present in the image (other than that of ENS-IFÉ for example)
You have to download them: - Choose a directory that will receive the sources and clone the mraa and upm repositories inside - create the build folder inside the mraa and upm folder and then enter this folder - prepare compilation with the cmake instruction - compiler installer - the new version is available!
mkdir -p Logiciels/IoT
cd Logiciels/IoT
git clone https://github.com/intel-iot-devkit/mraa.git
mkdir -p mraa/build
git clone https://github.com/intel-iot-devkit/mraa.git
mkdir -p upm/build
cd mraa/build
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make
sudo make install
cd ../../upm/build
cmake -DWERROR=off -DCMAKE_INSTALL_PREFIX:PATH=/usr ..
make
sudo make install
In October 2016, a change to the structure occurred at the request of the users, all the python modules in the upm library were grouped together in an upm
directory. This implies that the code is no longer imported directly. In programs older than this date, it is appropriate to replace
import pyupm_driveName
by
import upm
from upm import pyupm_DriverName as myName
You can then use myName
later which will lighten the notation.
The following chapters deal with the technique of constructing the ENS-IFÉ image which is proposed online.
Accompanying the use of the Raspberry Pi to learn the coding and remote control of weather sensors can be found in the article Learning how to code with weather in a web environment (LEDs, sensors, display ...)
3. How to Build a Debian Stretch Image
This section describes how to build a Debian Stretch image on a Raspberry Pi3 yourself. The rest of this article describes the work actually carried out to arrive at the image proposed at the end of the article and put online at the following addresses:
- [image Raspberry Pi 3] (http://mediaserv.climatetmeteo.fr/images/RaspBerry/DebianStretchPi3 /),
- [image Raspberry Pi 2] (http://mediaserv.climatetmeteo.fr/images/RaspBerry/DebianStretchPi2 /).
The construction of the image is based on a set of free scripts written by drtyhlpr and deposited on the GitHub opensource forge at: rpi23-gen-image. These scripts ensure all the work of downloading compilation and formatting of the image. Informed users will be able to directly use this resource according to their needs.
3.a Preparing the third-party computer to build the image
In order to speed up the creation process, we use another machine than the target Raspberry Pi to build the image, the following packages must be installed on the host machine:
debootstrap
debian-archive-keyring
qemu-user-static
binfmt-support
dosfstools
rsync bmap-tools
whois
git
bc
psmisc
. Test the presence of these packages and install them if necessary:
for i in debootstrap debian-archive-keyring qemu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc psmisc; Do dpkg -l $ i; done
Any missing package will be flagged by:
dpkg-query: no package matches ...
It must be installed
sudo apt-get install debootstrap debian-archive-keyring qmu-user-static binfmt-support dosfstools rsync bmap-tools whois git bc pmisc crossbuild-essential-armhf gparted wget 7z
I have added crossbuild-essential-armhf
gparted
wget
7z
packages which are also useful in the procedure below. It is also possible to create an armhf (chroot) development environment independent of the image creation process with the following commands:
qemu-debootstrap --arch = armhf sid / chroots / sid-armhf ftp://ftp.debian.org/debian/
chroot / chroots / sid-armhf
mount -t proc proc / proc
It can be used to produce packages or compile software more quickly using the power of a third-party computer. It installs on the emulation the sources and software needed to compile the desired programs.
Download the kernel to build the image (optional)
It is possible to choose the version of the kernel that we want to use for our image because the domain raspberrypi on git offers several. We will download version 4.X:
mkdir Kernel
cd Kernel
git clone -b rpi-4.X.y --single-branch https://github.com/raspberrypi/linux.git
The source code of the kernel decompresses into a folder named linux, we'll see how to use it later.
Download scripts rpi23-gen-image
Clone the GitHub repository in enough space to hold the software and the future image (from 1.5 GB to more than 3.5 GB)
git clone https://github.com/drtyhlpr/rpi23-gen-image.git
This action creates the rpi23-gen-image directory that contains all of the scripts and the main executable script. The templates folder contains a list of specific configurations that will be applied to our image
Itzawisis. €: ls -al
Total 852
drwxr-xr-x 8 vidal vidal 4096 Feb. 24 01:31 ./
drwxr-xr-x 9 vidal vidal 4096 Feb. 8 08:41 ../
drwxr-xr-x 2 vidal vidal 4096 Feb. 23 02:45 bootstrap.d /
-rw-r-r- 1 vidal vidal 714143 dec. 11 21:46 createrpi3.txt
drwxr-xr-x 15 vidal vidal 4096 Sep 7 16:02 files /
-rw-r-r- 1 vidal vidal 2153 Feb. 23 02:45 functions.sh
drwxr-xr-x 8 vidal vidal 4096 Feb. 23 19:37 .git /
-rw-r-r- 1 vidal vidal 43 Sep 7 16:02 .gitignore
drwxr-xr-x 3 vidal vidal 4096 Nov 24 23:49 images /
-rw-r-r- 1 vidal vidal 18092 Sep 7 16:02 LICENSE
drwxr-xr-x 2 vidal vidal 4096 dec. 4 18:46 packages /
-rw-r-r- 1 vidal vidal 23740 Feb. 23 02:45 README.md
-rwxr-xr-x 1 vidal vidal 19550 Feb. 23 02:45 rpi23-gen-image.sh *
-rwxr-xr-x 1 vidal vidal 18053 dec. 11 20:23 rpi3-gen-image.sh *
drwxr-xr-x 2 vidal vidal 4096 feb. 24 02:12 templates /
It is necessary to set a certain number of variables to produce an image corresponding to our needs. To simplify this action, it is proposed to group these parameters inside a file that is called by the main script. This makes it possible to simply reproduce the generation of an image. Templates is provided in the templates directory and you can simply add its own configuration file to this directory and it can be used by the creation process.
itzawisis. €: ls -al templates / total 32drwxr-xr-x 2 vidal vidal 4096 Feb. 24 02:12 ./drwxr-xr-x 8 vidal vidal 4096 Feb. 24 01:31 ../-rwxr-xr-x 1 vidal vidal 2416 Feb. 24 02:12 createraspife3 * -rwxr-xr-x 1 vidal vidal 2416 Feb. 24-04-07 rpi2j-rw-r-r- 1 vidal vidal 91 Jan 17 17:41 rpi2stretch-rw- R - r - 1 vidal vidal 102 Jan 17 17:41 rpi3jessie - rw - r - r - 1 vidal vidal 103 Jan 17 17:41 rpi3stretch
Creating a configuration file For image raspife3 and raspiife2
Raspberry Pi3
The image we are going to create will be named raspife3 to indicate that it is built for a Raspberry Pi3 of the project IFÉ Tremplin for the Teaching of Sciences. The creation parameters have been grouped in the createraspife3 file of the templates folder, this file is reproduced below:
#
APT_SERVER=ftp.fr.debian.org
APT_INCLUDES="gnupg,gnupg2,tightvncserver,build-essential,git,cmake,libjson-c-dev,\
bison,libboost-all-dev,automake,autoconf,libtool,pkg-config,checkinstall,python3,python3-dev,menulibre,\
libnotify-bin,python,python-configobj,python-cheetah,python-imaging,python-serial,python-usb,python-dev,\
pcre2-utils,libpcre++-dev,libpcre2-dev,libjpeg-dev,jed,wicd,i2c-tools,python-smbus,policykit-1,usbutils,\
pmount,python-pip,python3-pip,geany,geany-plugin-py,geany-plugin-markdown,firefox-esr,firefox-esr-l10n-fr,\
icedtea-8-plugin,openjdk-8-jdk,openjdk-8-jre,openjdk-8-jre-headless,libqtwebkit-dev,libqt5webkit5-dev,\
libudev-dev,libzzip-dev,zlib1g-dev,libcanberra-gtk-module,libnss-myhostname,libfreetype6-dev,libpng16-16,\
lxsession,openbox-lxde-session,lxde"
#----------------------
RPI_MODEL=3
RELEASE="stretch"
HOSTNAME="raspife3"
PASSWORD="**************"
USER_PASSWORD="************"
DEFLOCAL="fr_FR.UTF-8"
TIMEZONE="Europe/Paris"
EXPANDROOT=false
#-----------------------
XKB_MODEL="pc105"
XKB_LAYOUT="fr"
XKB_VARIANT="latin9"
XKB_OPTIONS=""
#------------------------
ENABLE_DHCP=true
#------------------------
ENABLE_CONSOLE=false
ENABLE_I2C=true
ENABLE_SPI=false
ENABLE_IPV6=true
ENABLE_SSHD=true
ENABLE_NONFREE=true
ENABLE_WIRELESS=true
ENABLE_RSYSLOG=true
ENABLE_SOUND=true
ENABLE_HWRANDOM=true
ENABLE_MINGPU=true
ENABLE_DBUS=true
ENABLE_XORG=true
ENABLE_WM="lxdm"
#------------------------
ENABLE_MINBASE=false
ENABLE_REDUCE=false
ENABLE_UBOOT=false
ENABLE_FBTURBO=true
ENABLE_IPTABLES=false
ENABLE_USER=true
USER_NAME=ens-ife
ENABLE_ROOT=true
ENABLE_HARDNET=true
ENABLE_INITRAMFS=true
ENABLE_IFNAMES=true
#------------------------
ENABLE_ROOT_SSH=false
SSH_LIMIT_USERS=false
SSH_ROOT_PUB_KEY="/home/vidal/.ssh/authorized_keys"
SSH_USER_PUB_KEY="/home/vidal/.ssh/authorized_keys"
#------------------------
BUILD_KERNEL=true
KERNEL_REDUCE=false
KERNEL_HEADERS=true
KERNEL_REMOVESRC=true
KERNELSRC_CLEAN=true
KERNELSRC_CONFIG=true
#------------------------
REDUCE_APT=false
REDUCE_DOC=true
REDUCE_MAN=false
REDUCE_HWDB=true
REDUCE_BASH=false
REDUCE_SSHD=false
REDUCE_LOCALE=false
#-------------------------
ENABLE_CRYPTFS=false
#-------------------------
BASEDIR=/pathTo/images/${RELEASE}
IMAGE_NAME=${BASEDIR}/${DATE}-rpi${RPI_MODEL}-${RELEASE}
In some configurations it was necessary to delete the preload of the lxde package so that the compilation succeeds, This case as soon as the image is finished (with lxdm) it is necessary to add the package lxde
sudo apt-get install lxde
Raspberry Pi2 (not updated)
The image we will create Will be named raspife2 to signal that it is built for a Raspberry Pi2 project IFÉ Tremplin for the Teaching of Sciences. All creation parameters have been grouped together in an executable file that launches the script to create the image. The contents of this file are reproduced below:
otinapa.€ : more createraspife2.sh
#! /bin/sh
APT_SERVER=ftp.fr.debian.org APT_INCLUDES="gnupg,gnupg2,firmware-realtek,firmware-linux-nonfree,firmware-linux,tightvncserver,build-essential,git,cmake,libjson-c-dev,automake,autoconf,libtool,pkg-config,checkinstall,python3,lxde,menulibre,libnotify-bin,python,python-configobj,python-cheetah,python-imaging,python-serial,python-usb,python-dev,pcre2-utils,libpcre++-dev,libpcre2-dev,libjpeg-dev,wicd,jed,i2c-tools,python-smbus,policykit-1,usbutils,pmount,python-pip,python3-pip,geany,geany-plugin-py,geany-plugin-markdown,libcanberra-gtk-module" RPI_MODEL=2 RELEASE=stretch HOSTNAME="raspife2" PASSWORD="AChanger1$" DEFLOCAL="fr_FR.UTF-8" TIMEZONE="Europe/Paris" EXPANDROOT=false XKB_MODEL="pc105" XKB_LAYOUT="fr" XKB_VARIANT="latin9" XKB_OPTIONS="" ENABLE_DHCP=true ENABLE_CONSOLE=false ENABLE_IPV6=true ENABLE_SSHD=true ENABLE_NONFREE=true ENABLE_RSYSLOG=false ENABLE_SOUND=true ENABLE_HWRANDOM=true ENABLE_MINGPU=true ENABLE_DBUS=true ENABLE_XORG=true ENABLE_WM="lxdm" ENABLE_FBTURBO=true ENABLE_USER=true USER_NAME=ens-ife ENABLE_ROOT=true ENABLE_ROOT_SSH=false ENABLE_INITRAMFS=true KERNEL_HEADERS=true BUILD_KERNEL=true REDUCE_APT=false REDUCE_DOC=true REDUCE_MAN=false REDUCE_HWDB=true REDUCE_BASH=false REDUCE_SSHD=false REDUCE_LOCALE=false ./rpi23-gen-image.sh
Comments on parameters used
Main differences between Raspberry Pi2 and Raspberry Pi3:
- The model of Raspberry Pi
- The name given to the machine
- There is no default WIFI and it can not be activated during creation
- Our Raspberry Pi is equipped with a mini USB WIFI realtek so we install realtek firmware in our image.
Details on the choice of variables:
- APT_SERVER is positioned on the host of the machine used, a generic value will be in France ftp.debian.fr
- APT_INCLUDES provides the list of debian packages that will be used later, which avoids having to install them later by hand
- RPI_MODEL provides model (2 or 3) of the Raspberry Pi
- HOSTNAME the name of the machine
- PASSWORD the password that will be changed
- DEFLOCAL specifies that we want an interface in French
- TIMEZONE defines our geographical position (attention the Raspberry Pi does not have a permanent clock, see the forums on it)
- ENABLE_WM I choose lxdm for its small size and its low consumption of resources by cons the universe proposed is a bit ... "austere"
- USER_NAME the first user with administrative rights is here
- Important KERNELSRC_DIR when present locates the path of the chosen kernel to build this image. By default and without this parameter the kernel is downloaded online from raspberrypi
The other variables set a certain number of parameters that are somewhat more technical than can be modified (provided the consequences of such a change are known)
Adding debian packages not included in repositories
For the Weather Climate Springboard project for science education, a number of bookshops of functions are required:
- WEEWX which provides a tool for communicating with a commercial weather station
- MRAA that provides low-level primitives to interact with the machine's GPIO or I2C bus not currently available as package (non-operational checkinstall), to be compiled on the new distribution
- UPM which provides drivers for a very large number of sensors or actuators. not currently available as a package (non-operational checkinstall), to be compiled on the new distribution
- A version of NODE compatible with mraa and upm (6.9.2) that is installed in the standard position (not in the Debian structure)
- A version of SWIG compatible with mraa and upm that is installed in the standard position (not in the Debian structure)
The situation is complex at the moment due to a lack of maintenance of the javascript part of the swig
software. Node
evolves very quickly and a number of functions used byswig
have been deprecated without being taken into account in swig
. It is therefore necessary not to use a Node
version higher than 6.9.2. However, a version compatible with node7 has been proposed and is being tested. As soon as it is validated, it will be integrated into the new image.
These software packages must either be compiled from source or loaded from Debian packages built by third parties but not in official repositories. Weewx
offers such an online package.
The swig
andnode
packages must be retrieved from the respective sites and installed because mraa
andupm
depend on it. In addition, a paragraph in the next chapter is devoted to the creation of these packages if a user wishes to carry out the entire procedure and to create these packages itself from the sources.
3.b Construction of the image
Before building the image it is necessary to create the package directory and place inside all the Debian packages external to the official repositories, whose compatibility with the system that will be created has been verified beforehand. This is not a circular reasoning! It is simply the expression of the fact that creating an image with rpi23gen is a very useful and efficient, but to benefit from it, it must be fed with resources that have been previously tested on a minimal image whose core is identical to that Which will be created (see above the creation of a machine with chroot and qemu). The packages proposed by the Tremplin project have been verified.
To add packages download them from the project drop-down and drop them in the packages directory:
cd rpi23-gen-image
mkdir pakages
cd packages
cp ~ / Downloads / weewx_3.6.2-1_all.deb.
Once the additional packages are available and the executable file contains all the parameters of the previous paragraph, you just need to run the following command:
cudo CONFIG_TEMPLATE = createraspife3 ./rpi23-gen-image.sh
The creation starts automatically and results in the creation of 2 files:
- The image itself (taking the date and ending with the .img estension)
- An attachment file to accelerate the copy of the image and considerably reduces the copy time on large microSD cards (taking the date and ending with the .bmap extension)
The bmap file can only be used with the bmap-tools software for which I have not found a windows version. The image is quite ordinary (created with the option sparse which has no influence on its usability) and can be copied with any tool capable of writing bit by bit on one Storage device.
Resize the size of the media that will hold the image
3.c Image Finishes
The end of the preparation of the picture happens on the raspberrypi. Copy the image to a microSD (see above) connect the raspberry to the wired network, look for its IP address and connect in ssh. The key installed during the creation is immediately operational and the first user created has sudo rights and then execute the following commands:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install systemd-sysv
mkdir -p Software / Node
cd Software
mkdir Swig
mkdir IoT
mkdir OpenZWave
For easy access to all the utilities and development environment for education set up around weather [presentation] (http://blog.climatetmeteo.fr/GerardVidal/meteo_jupyter_env.html) and [tools] ( https://github.com/g-vidal/Programmebook) it is desirable to carry out the installations proposed in [Chapter 5] (# head2). The next chapter describes the method used to add the software needed to implement the programs in the encoding environment and must also be installed.
All the installations and improvements described in Chapters 4 and 5 can be carried out without connecting the raspberry to a screen by simply knowing its address on the network and connecting it via ssh. Once the terminal server is installed it is possible to display on the third-party computer the graphical interface of the raspberrypi.
Once the image has been created, put it on an SD formatted in FAT32 (cf chapter 2), mount the SD then perform the following operations (check that the dist-packages directory does not already exist, 'Does not need to create it).
Creating default users
The automated creation of the image provided a single user for the smooth functioning of the development environment we need the following users:
- localadm (local administrator of Raspberry Pi),
- callisto (owner and launcher of Jupyterhub)
- moon (regular test user)
sudo adduser localadm
sudo adduser localadm sudo
sudo adduser callisto
sudo adduser moon
for i in ens-ife localadm callisto moon; do for j in i2c gpio netdev; do sudo adduser $ i $ j; done; done
for i in localadm ens-ife moon; do sudo adduser $ i jupyterhub; done
To improve security it is possible (desirable) to remove the login by password from callisto by providing an exclusive login by ssh key.
4. Manual construction of project-specific Debian packages Tremplin
These packages are those which are placed in the package directory of rpi23gen-image in order to directly build a complete image but it goes without saying that these packages that we propose online in the deposit Springboard were built by hand on an identical Raspberry Pi To the target we are targeting in the image, it is this procedure that is described here. The work is done on a Raspberry Pi built with the previous image (the one that is updated online) updated to exactly match the image sui is being created.
The swig and node packages are required for the compilation and operation of mraa and upm, but for the moment these two libraries are not configured to use the node and swig resources organized according to the Debian hierarchy, and mraa and upm often require More advanced versions of swig and node than those of the standard Debian distribution, which is why we offer these repackaged packages that work well with mraa and upm.
4.a The particular case of the weewx package
The weewx package is proposed by its author but a number of libraries are needed to configure weewx. These are: python, python-configobj, python-cheetah, python-imaging, python-serial, python-usb, libpcre2 -dev
, these libraries have been added to the initial configuration file and are added by default when building the image.
The weewx package is loaded and installed with the following commands:
wget http://weewx.com/downloads/weewx_3.6.2-1_all.deb
sudo dpkg -i weewx_3.6.2-1_all.deb
Provide the parameters corresponding to the station that will be connected via Weewx.
4.b Build / Install Package node
Depending on the distribution and the desired configuration it is possible to download a binary and install it or download the sources to compile and install them.
To use the binary
wget https://nodejs.org/dist/v7.6.0/node-v7.6.0-linux-armv7l.tar.xz
Tar xvfJ node-v7.6.0-linux-armv7l.tar.xz
cd node-v7.6.0-linux-armv7l
for i in bin include lib share; Do sudo cp -r $i/* /usr/local/$i; done
sudo ln -s /usr/local/bin/node /usr/local/bin/nodejs
sudo npm install -g node-gyp
sudo npm install -g configurable-http-proxy
To compile and install the package from the latest version of the sources, a number of packages are required:
sudo apt-get install build-essential git-core libssl-dev pkg-config libc-ares-dev zlib1g-dev devscripts
The sources are then recovered and compiled.
wget https://nodejs.org/dist/v6.9.2/node-v6.9.2.tar.gz
tar xfvz node-v6.9.2.tar.gz
cd node-v6.9.2
./configure
make
sudo checkinstall
The last command installs the node software and at the same time produces a debian package that was used to build the complete image and that can be reused as much as needed for all Raspberry Pi2 and 3 installs.
It is important to check that nodejs, node-gyp and the http proxy provided by node are present because the first two are necessary for Swig and the third necessary for the proper functioning of jupyterhub, it is also possibly used when creating a site Web in node on the Raspberry Pi. If not installed add them with the commands:
sudo npm install -g nodejs
sudo npm install -g node-gyp
sudo npm install -g configurable-http-proxy
4.c Construction of the swig package
The construction of the swig package depends on the packages pcre2-utils,libpcre++-dev,libpcre2-dev
which are added to the configuration file for the creation of the image in order to avoid users who wish to construct the image of have to load these dependencies by hand.
In order for swig to produce java executables, java must be available on the machine, so executables, include and node libraries must be linked. Same for javascript (it is therefore imperative to compile node before swig). We use here the version of swig modified by arfoll and update
wget https://github.com/g-vidal/swig/archive/master.zip
unzip master.zip
cd swig-master
./autogen.sh
./configure
make -j4
sudo make install
sudo ln -s /usr/include/webkitgtk-4.0/JavaScriptCore / usr / include / javaScriptCore
The nodejs and node-gyp packages must be installed in order to compile swig, but the new version of node (below) must be added to compile mraa and upm. Check the swig version before downloading and if necessary change the first two commands.
wget wget http://prdownloads.sourceforge.net/swig/swig-3.0.10.tar.gz
cd swig-3.0.10
./configure
make
sudo checkinstall
The last command installs the swig software and at the same time produces a debian package that was used to build the complete image and that can be reused autanT necessary for all installs of Raspberry Pi2 and 3.
4.d Building the package libopenzwave
OpenZWave is not available on arm platforms it is necessary to Compile it from sources. We will use the version of the repository github.
cd ~ / Software OpenSwitchGet clone https://github.com/OpenZWave/open-zwave.gitcd open-zwavemakesudo make install
4.e Construction of the mraa package
This operation can no longer be done in advance for the moment on a Raspberry Pi, it is necessary to build the libraries directly on the newly installed machine. To build the two INTEL packages (MRAA and UPM) it is necessary to have the opkg utilities developed by INTEL for its Yocto distribution. They must be installed from the git repository:
git clone https://github.com/shr-project/opkg-utils.git
make
sudo checkinstall
the opkg_1.0-1_armhf.deb
package is available in The.
MRAA directory is a low-level library allowing interaction with the GPIO bus. It is provided by INTEL under the GPL license on GitHub. Installation is done by cloning from the repository
git clone https://github.com/intel-iot-devkit/mraa.git
cd mraa
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX = / usr ..sudo make install
You will need to replace the last two lines with
cmake -DIPK = ON -DCMAKE_INSTALL_PREFIX = / usr ..
sudo checkinstall
For Yocto users it is possible to get ipk paste by running Command make package
, note that the debian build does not go well in the situation described here (perhaps because of unmet dependencies (to be examined).
The mraa_YYYYMMDD-1_armhf.deb
package is no longer manufactured By this method and it is advisable not to use it anymore [see discussion on git] (https://github.com/intel-iot-devkit/mraa/issues/60).
4.f Package build upm
UPM is a library of drivers for a gent number of sensors and microsensors that can be connected to the GPIO bus of the Raspberry Pi.This library can interact directly with a sensor or Effector with simple instructions that are in fact functions masking the complexity of programming an interface. However, it is still possible to pass parameters and to insert calls to these functions in high-level programs such as, for example, the administration of a weather station collecting and transmitting data. This operation can not be done in advance for the moment on a Raspberry Pi, it is necessary to build the libraries directly on the newly installed machine.
git clone https://github.com/intel-iot-devkit/upm.git
cd upm
mkdir build
cd build
cmake -DWERROR = off -DCMAKE_INSTALL_PREFIX = / usr ..
sudo make install
When the build of the packages will work again Replace the last two lines with
cmake -DIPK = ON -DCMAKE_INSTALL_PREFIX = / usr ..
sudo checkinstall
For Yocto users it is possible to get ipk paste by issuing the make package
command, Note that the debian build does not work well in the situation described here (perhaps because of unmet dependencies.) The upm_YYYYMMDD-1_armhf.deb
package is no longer manufactured by this method and is (See discussion on git) (https://github.com/intel-iot-devkit/mraa/issues/60).
4.g Settings and operation of created packages and postinstallation
If the 4 debian packages could be created they must be transferred to the host machine that builds the image in the home_rpi23-gen-image / packages
directory, they will then automatically be taken into account by the scripts and integrated into the picture. The weewx package will have to be reconfigured according to the parameters of the controlled station and if we do not wish to control a station, we will have to disable weewx which consumes in this case some resources sudo update-rc.d -f weewxd remove
.
For a chain production of the image it is necessary to carry out these modifications on an installed image and then to copy the image with modifications in order to propose images directly operational!
Activating the i2c bus
It is necessary to be able to use the i2c bus to activate it because in the default image, although everything is prepared it is not active. Two manipulations are necessary:
- Uncomment two lines of the
/ lib / modules-load.d / rpi2.conf
file to look like this
# Bcm2708_rng
snd_bcm2835
i2c-bcm2708
i2c-dev
# Rtc-ds1307
- Add the following two lines and the comments that precede it in the
/boot/firmware/config.txt
file
# Activate i2c0 i2c1
# I2c0 is used by the Raspberry Pi for other functions and
# Can not be used for direct sensors directly
dtoverlay = i2c0-bcm2708
dtoverlay = i2c1-bcm2708
In order to avoid using the root privileged command simply put users who will use the i2c bus in the i2c group with the command:
sudo adduser ens-ife i2c
[sudo] ens-ife password:
Adding the "ens-ife" user to the "i2c" group ...
Adding the ens-ife user to the i2c group
Done
For a list of groups to which a user belongs, use the commange groups
:
groups
ens-ife dialout cdrom floppy sudo audio video plugdev users i2c
Creation of gpio group and non-privileged access to this bus
Check if the gpio group exists and if not create it:
cat / etc / group | Grep gpio
gpio: x: 1001: ens-ife, vidal, callisto # the group is present otherwise
sudo addgroup gpio
In the /etc/udev/rulesd
directory create a 99-com.rules
file containing the following:
sudo jed /etc/udev/rulesd/99-com.rules
#ajouter
SUBSYSTEM=="gpio*", PROGRAM="/bin/sh -c 'chown -R root:gpio /sys/class/gpio && chmod -R 770 /sys/class/gpio; \
chown -R root:gpio /sys/devices/virtual/gpio && chmod -R 770 /sys/devices/virtual/gpio; \
chown -R root:gpio /sys/devices/platform/soc/3f200000.gpio && chmod -R 770 /sys/devices/platform/soc/3f200000.gpio; \
chown -R root:gpio /sys/devices/platform/soc/soc:virtgpio && chmod -R 770 /sys/devices/platform/soc/soc:virtgpio; \
chown -R root:gpio /sys/bus/platform/drivers/pinctrl-bcm2835 && chmod -R 770 /sys/bus/platform/drivers/pinctrl-bcm2835 '"
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add",
PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; \
chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; \
chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
These changes allow an ordinary user (non-root and non-sudo) to access resources on the gpio bus.
Network with automatic address acquisition (DHCP)
It is possible to preconfigure the wifi, for this connect your debian machine of installation to the network that you wish to preinstall in the Raspberry Pi, once connected go look
* Either the file with the name of your network in the / etc / NetworkManager directory and copy this file to the same directory of your Raspberry Pi, at the first start the Raspberry Pi will find the network and can connect to it;
* Either the part of the /etc/wicd/network.conf file about the configuration of the network to which you want to connect and copy it into the /etc/wicd/wireless-settings.conf
file.
Example of parameters for access to eduroam
[connection]
id=eduroam
uuid=*****************************
type=wifi
permissions=
secondaries=
[wifi]
mac-address=**:**:**:**:**:**
mac-address-blacklist=
mac-address-randomization=0
mode=infrastructure
seen-bssids=
ssid=eduroam
[wifi-security]
auth-alg=open
group=
key-mgmt=wpa-eap
pairwise=
proto=
[802-1x]
altsubject-matches=
eap=peap;
identity=vidal@ens-lyon.fr
password=******************
phase2-altsubject-matches=
phase2-auth=mschapv2
[ipv4]
dns-search=
method=auto
[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto
Do not forget to check that the user created by default (for us localadm) belongs to the netdev group, if not to add it otherwise it will not be able to activate or modify the WIFI.
It is possible that the resolver is configured for static use (especially if the wired network is used on the first connection) this is no problem if the machine stays on the same domain using the wired and The wifi. On the other hand, if the machine is able to connect from another network, it is necessary to pass the configuration file of the resolver in dynamic mode to do the following commands:
sudo rm /etc/resolv.conf
sudo ln -s /Run/systemd/resolve/resolv.conf /etc/resolv.conf
To finish if the network fails to run automatically on first login or to avoid leaving confidential traces Check the contents of the /etc/wicd/wired-settings.conf
and /etc / wicd / wireless-settings.conf
files. To reset these files (if you have not chosen to change the configuration manually as suggested above) use the following commands or edit the files and dump them manually.
sudo rm /etc/wicd/wired-settings.conf
sudo rm /etc/wicd/wireless-settings.conf
sudo touch /etc/wicd/wired-settings.conf
sudo touch /etc/wicd/wireless-settings.conf
sudo rm/etc/wicd/*~
The wired interface is unique and is created during the first connection, the image being installed by cloning it propagates the same interface number which is necessarily false. It will be necessary to change it so that the raspi can connect, the actual name of the active interface is obtained by the command:
ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2:enxb827eb3c732f: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether b8:27:eb:3c:73:2f brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:69:26:7a brd ff:ff:ff:ff:ff:ff
inet 10.0.1.14/24 brd 10.0.1.255 scope global wlan0
valid_lft forever preferred_lft forever
inet6 fe80::ba27:ebff:fe69:267a/64 scope link
valid_lft forever preferred_lft forever
The name of the interface is here enxb827eb3c732f.
This mode of operation is of course useful only if your Raspberry Pi acquires its IP automatically via DHCP, it stands to reason that if your Raspberry Pi has a fixed IP no need for this trick. The configuration of a fixed IP is not treated here.
5. Installation of services that can be used remotely
If you want to stop the Raspberry Pi command line install the following package that is excluded from the initial image for technical reasons, it is added in the IF-ENS image of Lyon.
sudo apt-get install systemd-sysv
5.a Installing a Remote Graphics Terminal Service
An elaborate way to achieve this goal is to have a user dedicated to terminal server access, create tsuser and use it:
sudo adduser tsuser
sudo su tsuser
vncpasswd
The password added by default is the name of the machine raspife3
The following file is then added to the /etc/init.d
directory named for example vncserver, the user * callisto * must possibly be changed according to the choices made.
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: vncserver
# Required-Start: networking
# Default-Start: S
# Default-Stop: 0 6
### END INIT INFO
PATH="$PATH:/usr/X11R6/bin/"
# The Username:Group that will run VNC
export USER="tsuser"
#${RUNAS}
# The display that VNC will use
DISPLAY="1"
# Color depth (between 8 and 32)
DEPTH="16"
# The Desktop geometry to use.
#GEOMETRY="<WIDTH>x<HEIGHT>"
#GEOMETRY="800x600"
GEOMETRY="1024x768"
#GEOMETRY="1280x1024"
# The name that the VNC Desktop will have.
NAME="my-vnc-server"
OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions
case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;
stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;
restart)
$0 stop
$0 start
;;
esac
exit 0
Make the file executable and install it in the application system at startup:
sudo chmod + x /etc/init.d/vncserver
sudo update-rc.d vncserver defaults
Vncserver is then a manipulable service like all the other services of the machine. Do not forget to stop it to avoid broadcaster permanently on the network.
Once the Raspberry Pi is started it is enough to look for a machine broadcasting on port 5901, note that we will find all the servers doing the broacast on this port ... One connects using a VNC client for example xvncviewer or remmina Or any other terminal server client!
If you do not intend to use this service (which is activated by default on the ENS image of Lyon IFÉ), you have to deactivate it to avoid consuming resources unnecessarily.
Sudo update-rc.d -f vncserver remove
Note that it is possible at any time to launch a terminal server on the Raspberry Pi with for example the vncserver service described above and to find on another computer a complete working environment provided by the Raspberry Pi. Forget to configure the parameters of its vncserver to have all the environment operational).
5.b Miscellaneous configurations for using python with the GPIO bus
The GPIO bus of the Raspberry Pi is not as complete and flexible as that of an Arduino or an Edison, each of these machines has specific properties resulting in different interactions with their GPIO bus. Moreover, since python is often used in training, jupyter and jupyterhub tools can be extremely powerful. This paragraph proposes a number of complementary but useful installations and configurations, which are exploited in the Springboard programming environment.
Installing virtual environments python
With the distribution stretch the two versions python2.7 and python3.5 cohabit without any problem however it can be interesting to develop independently these two universes. It is possible to install virtual environments with the command:
virtualenv -p python2.7 --system-site-packages VirtPython2
virtualenv -p python3.5 --system-site-packages VirtPython3
Installing additional libraries for the GPIO bus
The GPIO bus of the Raspberry Pi is quite particular to the point that there is a library built specifically for the Raspberry Pi. This library is very useful in some areas especially to change the number of pins in PWM mode useful for some programs see Jupyterhub program books.
This library is installed via pip (an update of the service packs is done before the installation):
sudo pip install setuptools
sudo pip install wheel --upgrade
sudo pip install Rpi.GPIO
sudo pip3 install setuptools
sudo pip install wheel --upgrade
sudo pip3 install Rpi.GPIO
5.c Installation of jupyter and jupyterhub
This point is also covered in the article [Learning to code with the weather in a web environment (LED, sensors, display ...)] (http://blog.climatetmeteo.fr/GerardVidal/meteo_jupyter_env.html)
sudo pip install jupyter
sudo pip -no-cache-dir install matplotlib (because of the low memory of the raspi)
sudo pip3 install jupyter
sudo pip3 install jupyterhub
sudo pip3 install git + https: //github.com/jupyter/sudospawner
sudo pip3 --no-cache-dir install matplotlib (because of the low memory of the raspi)
Installing program booklets in the test user environments assumes here that the starting point is the preferred user ens-ife, repeating the manipulation in the environments of all users who will use the program booklets.
git clone https://github.com/g-vidal/Programmag.git
sudo su moon
git clone https://github.com/g-vidal/Programmag.git
exit
Creating an authentication certificate to protect exchanges between raspberry and clients and configuring jupyterhub.
Security is a crucial step in any exchange over a digital network. Even if your raspberry who is plugged into a TP room behind the firewall of the facility does not seem to be a threat, it could well become one! (This is very fashionable not at this moment in the US series to use Pi Raspberries as digital attack instruments, this is usually fictionalized but actually based on reality).
There is no need for an overriding security policy. On the other hand, it is imperative to put in place a few basic elements of protection which can also serve as a support for an awareness of the numerical risks and Adopt on networks. Authentication allows each group or student (according to the choice of the teacher) to have a protected area of the actions of the rest of the world.
Callisto is by default the user who launches jupyterhub, so to preserve the proposed configuration it is the user callisto who must create a new certificate.
cd ~
mkdir -p Utils / Certificates
cd Utils / Certificates
openssl req -new -newkey rsa: 2048 -rand / dev / urandom -nodes -keyout meteojuphub.key -out meteojuphub.csr
# Answer questions with your information
openssl req -new -x509 -days 3652 -key meteojuphub.key -out meteojuphub.pem
# Answer questions with your information
The certificate must be enabled for jupyterhub at the root of the user callisto, in the Jupyterhub directory (it is present by default in the ENS-IFÉ image)
mkdir Jupyterhub
cd ~ / Jupyterhub
mkdir config
jupyterhub --generate-config
Edit the jupyterhub_config.py
file by uncommenting and entering the 3 lines below:
# c.JupyterHub.spawner_class = 'jupyterhub.spawner.LocalProcessSpawner'
c.JupyterHub.spawner_class = 'sudospawner.SudoSpawner'
## Path to SSL certificate for the public interface of the proxy
#
# Use with ssl_key
c.JupyterHub.ssl_cert = '/home/callisto/Utils/Certificates/meteojuphub.pem'
## Path to SSL key file for the public interface of the proxy
#
# Use with ssl_cert
c.JupyterHub.ssl_key = '/home/callisto/Utils/Certificates/meteojuphub.key'
## set of usernames of admin
#
# If unspecified, the server will be admin.
c.Authenticator.admin_users = set (['loginAdminName', 'othername'])
To run the user who launches jupiterhub must have a number of privileges that are added to the sudoers file:
sudo visudo
Add the following lines to the end of the /etc/sudoers
file
# The command (s) the hub can run on behalf of the jupyterhub group users
# Without having a password
# The exact path may differ, depending on how sudospawner was installed
cmnd_Alias JUPYTER_CMD = /usr/local/bin/sudospawner
# Actually give the Hub
# Of the above users without prompting for a password
callisto ALL = (% jupyterhub) NOPASSWD: JUPYTER_CMD
The user must also belong to the jupyterhub group and to the shadow group. If the jupyterhub group has not yet been created, users must be assigned to it.
sudo addgroup jupyterhub
sudo adduser userhublauncher jupyterhub
sudo adduser userhublauncher shadow
Create a command file in /home/callisto/Jupyter to keep the command line and run it through the filename to simplify.
cat > hubStartCommand.sh
#!/bin/bash
jupyterhub --JupyterHub.spawner_class=sudospawner.SudoSpawner
ctrl-D
chmod a+x hubStartCommand.sh
Installing the node http proxy if it is not already present:
sudo npm install -g configurable-http-proxy
Without this jupyterhub software can notFunction.
6. Image propagation
You can also move all the folders you want to use later into /home/localadm
. If they are in the image you will not have to copy them n times for the n created images. Once all postinstallation manipes are done disassemble the SD then copy its contents on the hard disk (make sure to have the Place required the size of the image may vary)
sudo dd if=/dev/sdh of=2017-01-17-debianStretchRpi3.img bs=8M conv=sparse count=900
[sudo] Mot de passe de vidal :
900+0 enregistrements lus
900+0 enregistrements écrits
7549747200 bytes (7,5 GB, 7,0 GiB) copied, 232,419 s, 32,5 MB/s
I chose to limit the size of my image to 7.5GB So that it can hold in an SD of 8GB, we saw above that the initial effective size of the compiled image was less than 2GB which leaves room for margins even after the installation of the additional packets. Once the image has been copied, it is necessary to redo its bmap:
bmaptool create -o 2017-01-17-debianStretchRpi3.bmap 2017-01-17-debianStretchRpi3.img
The resulting image and its bmap Are now diffuseable but it is desirable to compress the image which if not is a bit .... encombrante
7z a -txz 2017-01-17-debianStretchRpi3.img.xz ./2017-01-17-debianStretchRpi3.img
7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=fr_FR.UTF-8,Utf16=on,HugeFiles=on,64 bits,12 CPUs Intel(R) Xeon(R) CPU W3680 @ 3.33GHz (206C2),ASM,AES-NI)
Scanning the drive:
1 file, 7549747200 bytes (7200 MiB)
Creating archive: 2017-01-17-debianStretchRpi3.img.xz
Items to compress: 1
Files read from disk: 1
Archive size: 1802331200 bytes (1719 MiB)
Everything is Ok
Commentaires